package Controllers;

import java.rmi.RemoteException;

import Common.Helper;
import Models.ChessPieceModel;
import Models.Point2D;
import Models.StandardChessPieceModel;

public class KingController implements ChessPieceControllerInterface {

	@Override
	public boolean legalMove(Point2D moveVector, ChessPieceModel chessPiece) throws RemoteException {
		if (moveVector.getX() == 0 && moveVector.getY() == 1 || moveVector.getY() == -1) {
			return true;
		}
		else if (moveVector.getX() == 1 && (moveVector.getY() == 1 || moveVector.getY() == 0 || moveVector.getY() == -1)) {
			return true;
		}
		else if (moveVector.getX() == -1 && (moveVector.getY() == -1 || moveVector.getY() == 0 || moveVector.getY() == 1)) {
			return true;
		}
		else {
		
		return false;
		}
	}

	


	@Override
	public boolean legalCapture(Point2D moveVector, ChessPieceModel chessPiece) throws RemoteException {
		// TODO Auto-generated method stub
		return legalMove(moveVector, chessPiece);
	}

	@Override
	public boolean canPieceMoveNotify(Point2D from, Point2D to,
			ChessPieceModel chessPiece) throws RemoteException {
		return legalMove(Helper.calculateVector(from, to), chessPiece);
		}
		
		
		public static ChessPieceModel getNew() throws RemoteException {
			ChessPieceModel king = new StandardChessPieceModel();
			ChessPieceControllerInterface kingController = new KingController();
			king.addCanPieceMoveListener(kingController);
			return king;
		}

	
	

}
